#! /usr/bin/python

def my_factorial(n):
    if n == 1:
        return 1
    else:
        return n * my_factorial(n - 1)

def my_power(x, n):
    if n == 0:
        return 1
    else:
        return x * my_power(x, n - 1)

def binary_search(seq, number, lower = 0, upper = None):
    if upper == None:
        upper = len(seq) - 1
    if lower == upper:
        assert number == seq[upper]
        return upper
    else:
        middle = (lower + upper) // 2
        if number > seq[middle]:
            return binary_search(seq, number, middle + 1, upper)
        else:
            return binary_search(seq, number, lower, middle)

def main():
    print my_factorial(5)
    print my_power(3, 3)

    seq = [23, 34, 3, 59, 35, 82, 30, 15, 99, 124, 56]
    seq.sort()
    print seq
    print 'Find 15: ' + str(binary_search(seq, 15))
    print 'Find 99: ' + str(binary_search(seq, 99))
    print 'Find 30: ' + str(binary_search(seq, 30))
    print 'Find 40: ' + str(binary_search(seq, 40))


if __name__ == '__main__':
    main()
